﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 视频设备
{
    public partial class 观众账号登录 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Image1.ImageUrl = "../WebForm1.aspx";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {           
            var checkCode = TextBox3.Text.Trim();
            生成验证码.YanZhengResult yanResult = 生成验证码.CheckCodeSame(checkCode);
            switch (yanResult )
            {
                case  生成验证码 .YanZhengResult .Fail :
                Response.Write("<Script Language='JavaScript'>window.alert('校验码错误！请重新输入！');window.close();</script>");
                break;
                case 生成验证码.YanZhengResult.Success :
                Login();
                break;
                case 生成验证码.YanZhengResult.CodeNull :
                Response.Write("<Script Language='JavaScript'>window.alert('请获取验证码！')</script>");
                break;
            }
            
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
           
        }


        //检验用户名和密码是否一致
        void Login()
        {
            观众账号 sh = new 观众账号();
            var name = TextBox1.Text;
            var mima = TextBox2.Text;
            观众账号集.AuthResult authResult = 观众账号集.auth(name, mima);
            switch (authResult)
            {
                case 观众账号集.AuthResult.Locked:
                    Response.Write("抱歉!您没有访问权限!");
                    break;
                case 观众账号集.AuthResult.Sucess:
                    HttpContext.Current.Session["Users"] = name;
                    RouteData.Values["UserDefinedURL"] = HttpContext.Current.Session["Users"];
                    //RouteData.Values["UserDefinedURL"] = name;
                    //Response.Redirect("视频.aspx");
                    Server.Transfer("视频.aspx");                    
                    break;
                case 观众账号集.AuthResult.PassworDoesnotMatch:
                    Response.Write("抱歉!您的用户名和密码不匹配!");
                    break;
            }           
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Image1.ImageUrl = "../WebForm1.aspx";
        }
    }
}